package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoleDto;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@Api(tags = "角色管理")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页查询角色信息")
    public ResponseResult querPage(@RequestBody RoleDto roleDto, @PathVariable Integer pageNum, @PathVariable Integer pageSize){
       PageResponse<RoleVo> page=roleService.querPage(roleDto, pageNum, pageSize);
       return ResponseResult.success(page);
    }

    @PutMapping
    @ApiOperation(value = "角色添加")
    public ResponseResult addRole(@RequestBody RoleDto roleDto){
        roleService.addRole(roleDto);
        return ResponseResult.success();
    }

    @GetMapping("/find-checked-resources/{roleId}")
    @ApiOperation(value = "根据角色查询选中的资源数据")
    public ResponseResult findCheckedResources(@PathVariable Long roleId){
      List<String> list= roleService.findCheckedResources(roleId);
        return ResponseResult.success(list);
    }


    @PatchMapping
    @ApiOperation(value = "角色修改+启用禁用")
    private ResponseResult updateRole(@RequestBody RoleDto roleDto){
        roleService.updateRole(roleDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/{roleId}")
    @ApiOperation(value = "角色删除")
    public ResponseResult deleteRole(@PathVariable Long roleId){
        roleService.deleteRole(roleId);
        return ResponseResult.success();
    }

    @PostMapping("/init-roles")
    @ApiOperation(value = "角色下拉框")
    public ResponseResult roleDropdownMenu(){
        List<RoleVo> list=roleService.roleDropdownMenu();
        return ResponseResult.success(list);
    }

}
